package org.yuangu.privacyfinance.helpers;

import android.content.Context;
import com.privacy.accountmgr.R;
import org.yuangu.privacyfinance.domain.model.RepeatingTransaction;

/**
 * Helper class that forges string representations of repeating intervals for repeating transactions.
 */
public final class RepeatingHelper {
    private RepeatingHelper() {}

    public static String forgeRepeatingText(Context context, RepeatingTransaction repeatingTransaction) {
        String template = null;
        if (repeatingTransaction.getEnd() != null) {
            // Not forever
            template = context.getString(R.string.repeat_text_unit_until_template);
            template = template.replace("UNTIL", repeatingTransaction.getEnd().toString());
        } else {
            //Forever
            template = context.getString(R.string.repeat_text_unit_template);
        }

        if (repeatingTransaction.isWeekly()) {
            if (repeatingTransaction.getInterval() == 1) {
                template = template.replace("UNITTTT", context.getString(R.string.repeat_unit_every_first_week));
            } else {
                String week = context.getString(R.string.repeat_unit_every_n_week);
                week = week.replace("NNNN", String.valueOf(repeatingTransaction.getInterval()) + ".");
                template = template.replace("UNITTTT", week);
            }
        } else {
            if (repeatingTransaction.getInterval() == 1) {
                template = template.replace("UNITTTT", context.getString(R.string.repeat_unit_every_first_month));
            } else {
                String month = context.getString(R.string.repeat_unit_every_n_month);
                month = month.replace("NNNN", String.valueOf(repeatingTransaction.getInterval()) + ".");
                template = template.replace("UNITTTT", month);
            }
        }

        return template;
    }
}
